FROM alpine:3

COPY docker-entrypoint.sh /
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk --update upgrade \
    && apk add bind bind-tools bind-plugins \
    && mkdir -m 0750 -p /etc/bind \
    && chown -R root:named /etc/bind \
    && mkdir -m 0770 -p /var/cache/bind \
    && chown -R named:named /var/cache/bind \
    && wget -q -O /etc/bind/bind.keys https://ftp.isc.org/isc/bind9/keys/9.11/bind.keys.v9_11 \
    && rndc-confgen -a \
    && cp /etc/bind/rndc.key /rndc.key \
    && cp /etc/bind/bind.keys /bind.keys \
    && chmod 0755 /docker-entrypoint.sh

COPY configs/. /etc/bind/

VOLUME ["/etc/bind"]
VOLUME ["/var/cache/bind"]

EXPOSE 53 53/udp

ENTRYPOINT ["/docker-entrypoint.sh"]
